function JCAdminTitleSearch(e){var t=this;this.arParams={AJAX_PAGE:e.AJAX_PAGE,CONTAINER_ID:e.CONTAINER_ID,INPUT_ID:e.INPUT_ID,MIN_QUERY_LEN:parseInt(e.MIN_QUERY_LEN)};if(e.WAIT_IMAGE)this.arParams.WAIT_IMAGE=e.WAIT_IMAGE;if(e.MIN_QUERY_LEN<=0)e.MIN_QUERY_LEN=1;this.cache=[];this.cache_key=null;this.startText="";this.currentRow=-1;this.RESULT=null;this.CONTAINER=null;this.INPUT=null;this.WAIT=null;this.Hide=function(){t.RESULT.style.display="none";t.RESULT.innerHTML="";t.currentRow=-1;t.UnSelectAll();BX.removeClass(t.INPUT.parentNode,"adm-header-search-block-active-popup")};this.ShowResult=function(e){this.AdjustResult();if(e!=null){t.RESULT.innerHTML=e;setTimeout(this.AdjustResult,50)}if(t.RESULT.innerHTML.length>0){t.RESULT.style.display="block";BX.addClass(t.INPUT.parentNode,"adm-header-search-block-active-popup")}else{this.Hide()}};this.AdjustResult=function(e){var s=BX.pos(t.CONTAINER);s.width=s.right-s.left;t.RESULT.style.position="absolute";t.RESULT.style.top="4px";t.RESULT.style.left=s.left-7+"px";t.RESULT.style.width=s.width+14+"px"};this.onKeyPress=function(e){var s=BX.findChild(t.RESULT,{tag:"table",class:"adm-search-result"},true);if(!s)return false;var a=s.rows.length;switch(e){case 27:t.Hide();return true;case 40:if(t.RESULT.style.display=="none")t.RESULT.style.display="block";var i=-1;for(var n=0;n<a;n++){if(i==-1)i=n;if(t.currentRow<n){t.currentRow=n;break}else if(s.rows[n].className=="adm-search-selected"){s.rows[n].className=""}}if(n==a&&t.currentRow!=n)t.currentRow=i;s.rows[t.currentRow].className="adm-search-selected";return true;case 38:if(t.RESULT.style.display=="none")t.RESULT.style.display="block";var r=-1;for(var n=a-1;n>=0;n--){if(r==-1)r=n;if(t.currentRow>n){t.currentRow=n;break}else if(s.rows[n].className=="adm-search-selected"){s.rows[n].className=""}}if(n<0)t.currentRow=r;s.rows[t.currentRow].className="adm-search-selected";return true;case 13:if(t.RESULT.style.display=="block"){for(var n=0;n<a;n++){if(t.currentRow==n){if(!BX.findChild(s.rows[n],{class:"adm-search-separator"},true)){var o=BX.findChild(s.rows[n],{tag:"a"},true);if(o){window.location=o.href;return true}}}}}return false}return false};this.onTimeout=function(){if(t.INPUT.value!=t.oldValue&&t.INPUT.value!=t.startText){if(t.INPUT.value.length>=t.arParams.MIN_QUERY_LEN){t.oldValue=t.INPUT.value;t.cache_key=t.arParams.INPUT_ID+"|"+t.INPUT.value;if(t.cache[t.cache_key]==null){if(t.WAIT){var e=BX.pos(t.INPUT);var s=e.bottom-e.top-2;t.WAIT.style.top=e.top+1+"px";t.WAIT.style.height=s+"px";t.WAIT.style.width=s+"px";t.WAIT.style.left=e.right-s+2+"px";t.WAIT.style.display="block"}BX.ajax.post(t.arParams.AJAX_PAGE,{ajax_call:"y",INPUT_ID:t.arParams.INPUT_ID,q:t.INPUT.value},function(e){t.cache[t.cache_key]=e;t.ShowResult(e);t.currentRow=-1;t.EnableMouseEvents();if(t.WAIT)t.WAIT.style.display="none";setTimeout(t.onTimeout,500)})}else{t.ShowResult(t.cache[t.cache_key]);t.currentRow=-1;t.EnableMouseEvents();setTimeout(t.onTimeout,500)}}else{t.Hide();setTimeout(t.onTimeout,500)}}else{setTimeout(t.onTimeout,500)}};this.UnSelectAll=function(){var e=BX.findChild(t.RESULT,{tag:"table",class:"adm-search-result"},true);if(e){var s=e.rows.length;for(var a=0;a<s;a++)e.rows[a].className=""}};this.EnableMouseEvents=function(){var e=BX.findChild(t.RESULT,{tag:"table",class:"adm-search-result"},true);if(e){var s=e.rows.length;for(var a=0;a<s;a++){e.rows[a].id="row_"+a;e.rows[a].onmouseover=function(e){if(t.currentRow!=this.id.substr(4)){t.UnSelectAll();this.className="adm-search-selected";t.currentRow=this.id.substr(4)}};e.rows[a].onmouseout=function(e){this.className="";t.currentRow=-1}}}};this.onFocusLost=function(e){setTimeout(function(){t.Hide()},250)};this.onFocusGain=function(){if(t.RESULT.innerHTML.length)t.ShowResult()};this.onKeyDown=function(e){if(!e)e=window.event;if(t.RESULT.style.display=="block"){if(t.onKeyPress(e.keyCode))return BX.PreventDefault(e)}};this.Init=function(){this.CONTAINER=document.getElementById(this.arParams.CONTAINER_ID);if(document.getElementById("bx-panel")){this.RESULT=document.getElementById("bx-panel").appendChild(document.createElement("DIV"));this.RESULT.className="adm-search-result-wrap";this.RESULT.style.display="none"}this.INPUT=document.getElementById(this.arParams.INPUT_ID);this.startText=this.oldValue=this.INPUT.value;BX.bind(this.INPUT,"focus",function(){t.onFocusGain()});BX.bind(this.INPUT,"blur",function(){t.onFocusLost()});BX.bind(window,"resize",function(){t.onFocusGain()});this.INPUT.onkeydown=this.onKeyDown;if(this.arParams.WAIT_IMAGE){this.WAIT=document.body.appendChild(document.createElement("DIV"));this.WAIT.style.backgroundImage="url('"+this.arParams.WAIT_IMAGE+"')";if(!BX.browser.IsIE())this.WAIT.style.backgroundRepeat="none";this.WAIT.style.display="none";this.WAIT.style.position="absolute";this.WAIT.style.zIndex="1100"}setTimeout(this.onTimeout,500)};BX.ready(function(){t.Init(e)})}